<?php

App::uses('Shell', 'Console');

class BaseParser extends Shell {
    protected $estacaoId;
    protected $content;

    public function setEstacaoId($estacaoId) {
    	$this->estacaoId = $estacaoId;
    }

	public function setContent($content) {
    	$this->content = $content;
    }

    protected function getNumSequencia($date) {
		$leituras = $this->{$this->modelClass}->find('first',
			array(
				'conditions' => array(
					'hora'			=> $date,
					'estacao_id'	=> $this->estacaoId
				),
				'fields' => 'sequencia',
				'order' => array(
					'sequencia' => 'DESC'
				),
				'recursive' => -1,
				'callback' => false
			)
		);

		if (count($leituras) > 0)
			$sequencia = intval($leituras[$this->modelClass]['sequencia']) + 1;
		else
			$sequencia = 1;

		return $sequencia;
    }

    protected function convertToDateSql($date) {
    	$myDateTime = DateTime::createFromFormat('d/m/Y H:i:s', $date);
    	if ($myDateTime == null)
    		return '';
    	
        return $myDateTime->format('Y-m-d H:i:s');
    }
}